Skip to content

Docs: Recommend using bound function reference instead of watch=True in bind_component guide - #8479

Merged
philippjfr merged 3 commits into
holoviz:mainfrom
Macdrita:docs-bind-reference
Mar 9, 2026
Merged

Docs: Recommend using bound function reference instead of watch=True in bind_component guide#8479
philippjfr merged 3 commits into
holoviz:mainfrom
Macdrita:docs-bind-reference

Conversation

@Macdrita

@Macdrita Macdrita commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #6271

This PR updates the documentation in doc/how_to/interactivity/bind_component.md to clarify the recommended pattern for using pn.bind when updating component parameters.

Users coming from param.watch() patterns may attempt to use watch=True with pn.bind. However, this pattern recreates the object whenever the inputs change and is generally considered an anti-pattern.

This PR adds a section explaining that a better approach is to assign the bound function directly to the relevant component parameter. For example:

def update_value(select_value, slider_value):
    return select_value * slider_value

text = pn.widgets.StaticText(value=pn.bind(update_value, select, slider))

This approach keeps the component reactive while avoiding unnecessary object recreation and ensures that only the relevant parameter is updated.

The documentation change clarifies the intended usage of pn.bind and improves guidance for users working with reactive components.


How Has This Been Tested?

This change only modifies documentation.

The updated section was reviewed locally to ensure:

  • Correct Markdown formatting
  • Proper placement within the existing guide
  • Consistency with surrounding documentation examples

Since this is a documentation-only change, no runtime functionality or tests were affected.


AI Disclosure

  • This PR contains AI-generated content.
  • I have tested all AI-generated content in my PR.
  • I take responsibility for all AI-generated content in my PR.

Tools: ChatGPT


Checklist

  • Tests added and is passing
  • Added documentation

@ahuang11 ahuang11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing

Comment thread doc/how_to/interactivity/bind_component.md
Comment thread doc/how_to/interactivity/bind_component.md
Macdrita and others added 2 commits March 7, 2026 16:38
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
@philippjfr
philippjfr merged commit 472afef into holoviz:main Mar 9, 2026
1 check passed
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update docs to use the bound function as a reference

3 participants